package com.ys.zero.dao;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ys.zero.bean.Uarticle;
import com.ys.zero.util.DBHelper;

/**
 * 用户后台Dao方法
 * @author Administrator
 *
 */
public class UserbackDao {
	/**
	 * 查询文章
	 * @param uid
	 * @return
	 */
	public List<Uarticle> getArticle(Integer uid) {
		String sql = "select * from uarticle where uid = ?";
		return DBHelper.query(sql,Uarticle.class,uid);
	}
	/**
	 * 删除文章
	 * @param uaid
	 */
	public void delArticle(String uaid) {
		String sql = "delete from uarticle where uaid = ?";
		try {
			DBHelper.update(sql,uaid);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public List<Map<String, Object>> MyCollaction(String account) {
		try {
			String sql = "SELECT * from collection a join uarticle  b on  a.cuaid = b.uaid where a.cformat=0 and a.caccount = ?";
			return DBHelper.selectList(sql,account);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	public int insertResource(String account, String resourceName, String resourceDescription, String resourceLabel, String resourceClassification, String resourceForm,String rcategory,String raddress) {
		String sql = "insert into resource(rworker,rname,rdescribe,rlabel,rtype,rdate,rcategory,raddress) values(?,?,?,?,?,now(),?,?)";
		try {
			DBHelper.update(sql, account,resourceName,resourceDescription,resourceLabel,resourceClassification,rcategory,raddress);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0 ;
	}
//	public static void main(String[] args) {
//		String s="abc.jpg";
//	    //String regex=".+?//.(.+)";这种写法也是可以的，但我认为没有后面的精确
//	    String regex=".+?//.([a-zA-z]+)";
//	    Pattern pt=Pattern.compile(regex);
//	    
//	    Matcher mt=pt.matcher(s);
//	    if(mt.find())
//	    {
//	      System.out.println(mt.group(1));
//	    }
//	}
	
}
